package com.cykj.pos.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.pos.domain.BizMerchant;
import com.cykj.pos.domain.BizPosMachine;
import com.cykj.pos.domain.SynchronizationDataDTO;
import com.cykj.pos.domain.dto.TeamOverviewDTO;
import com.cykj.pos.domain.dto.TransactionDetailsDTO;
import com.cykj.pos.enums.bizstatus.CommEnum;
import com.cykj.pos.profit.dto.HomePageDataDTO;
import com.cykj.pos.profit.dto.MerchantDTO;
import com.cykj.pos.profit.dto.PartnerDetailDTO;
import com.cykj.pos.service.IPosTransactionNoticeService;
import com.cykj.pos.util.LoginUserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 许晓龙
 * @date 2025/1/21 15:40
 */

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/notice/new")
@Api(tags = "新交易接口")
public class PosTransactionNoticeController {

    private final IPosTransactionNoticeService iPosTransactionNoticeService;

    @ApiOperation("交易")
    @PostMapping("/transaction")
    public Map transact(@RequestBody SynchronizationDataDTO sy) {

        System.out.println("------------------------------------------------------------------");
        System.out.println("--------pos1.0交易通知：" + JSONObject.toJSONString(sy) + "---------");
        System.out.println("------------------------------------------------------------------");
        //转换时间格式
        String year = sy.getHost_date().substring(0, 4);
        String month = sy.getHost_date().substring(4, 6);
        String day = sy.getHost_date().substring(6, 8);
        String hour = sy.getHost_time().substring(0, 2);
        String minute = sy.getHost_time().substring(2, 4);
        String second = sy.getHost_time().substring(4, 6);
        String date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
        sy.setHost_date(date);
        if (291 == sy.getTrans_type()){ // 星驿付没有单独的押金通知。此判断为星驿付押金
            return iPosTransactionNoticeService.deposit(sy);
        }
        return  iPosTransactionNoticeService.transact(sy);
    }

    @ApiOperation("押金流量")
    @PostMapping("/depositAndSimFee")
    public Map depositAndSimFee(@RequestBody SynchronizationDataDTO sy) {
        System.out.println("-------------------------------------------------------------------");
        System.out.println("--------pos1.0交易通知：" + JSONObject.toJSONString(sy) + "----------");
        System.out.println("----------------------------------------------------------------------");
        //转换时间格式
        String year = sy.getHost_date().substring(0, 4);
        String month = sy.getHost_date().substring(4, 6);
        String day = sy.getHost_date().substring(6, 8);
        String hour = sy.getHost_time().substring(0, 2);
        String minute = sy.getHost_time().substring(2, 4);
        String second = sy.getHost_time().substring(4, 6);
        String date = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
        sy.setHost_date(date);
        if (291 == sy.getTrans_type()){ // 押金
            return iPosTransactionNoticeService.deposit(sy);
        }else if (293 == sy.getTrans_type()){ // 流量费
            return iPosTransactionNoticeService.simFee(sy);
        }
        return null;
    }

    @ApiOperation("交易明细")
    @PostMapping("/transaction/details")
    public AjaxResult transactionDetails(@RequestBody TransactionDetailsDTO detailsDTO) {
        return  iPosTransactionNoticeService.transactionDetails(detailsDTO);
    }

    @ApiOperation("今日统计")
    @PostMapping("/today/statistics")
    public AjaxResult todayStatistics(@RequestBody TransactionDetailsDTO detailsDTO) {
        return  iPosTransactionNoticeService.todayStatistics(detailsDTO);
    }

    /**
     * 废弃
     * @param merchantDTO
     * @return
     */
    @ApiOperation("团队交易额柱状图")
    @PostMapping("/number/of/team/transaction")
    public AjaxResult numberOfTeamTransaction(@RequestBody MerchantDTO merchantDTO) {
        AjaxResult ajaxResult = AjaxResult.success();
        List<PartnerDetailDTO> partnerDetailDTOList = iPosTransactionNoticeService.numberOfTeamTransaction(merchantDTO);
        ajaxResult.put("data", partnerDetailDTOList);
        return ajaxResult;

    }

    /**
     * 废弃
     * @param merchantDTO
     * @return
     */
    @ApiOperation("团队激活柱状图")
    @PostMapping("/number/of/team/activations")
    public AjaxResult numberOfTeamActivations(@RequestBody MerchantDTO merchantDTO) {
        AjaxResult ajaxResult = AjaxResult.success();
        List<PartnerDetailDTO> partnerDetailDTOList = iPosTransactionNoticeService.numberOfTeamActivations(merchantDTO);
        ajaxResult.put("data", partnerDetailDTOList);
        return ajaxResult;

    }

    /**
     * 废弃
     * @param detailsDTO
     * @return
     */
    @ApiOperation("新首页") // 废弃
    @PostMapping("/new/homePage/data")
    public AjaxResult homePageData(@RequestBody TransactionDetailsDTO detailsDTO) {
        return  iPosTransactionNoticeService.homePageData(detailsDTO);
    }

    @ApiOperation("首页交易收益激活")
    @PostMapping("/homePage/trade/income/activate")
    public AjaxResult homePageTradeIncomeActivate(@RequestBody TransactionDetailsDTO detailsDTO) {
        return  iPosTransactionNoticeService.homePageTradeIncomeActivate(detailsDTO);
    }

    @ApiOperation("团队概况")
    @PostMapping("/homePage/team/overview")
    public AjaxResult homePageTeamOverview(@RequestBody TeamOverviewDTO teamOverviewDTO) {
        return  iPosTransactionNoticeService.homePageTeamOverview(teamOverviewDTO);
    }

    @ApiOperation("嘉联VIP")
    @PostMapping("/jl/vip")
    public AjaxResult jlVip(@RequestBody JSONObject param) {
        return  iPosTransactionNoticeService.jlVip(param);
    }

    @ApiOperation("嘉联修改费率")
    @PostMapping("/jl/updateFee")
    public AjaxResult jlUpdateFee(@RequestBody JSONObject param) {
        return  iPosTransactionNoticeService.jlUpdateFee(param);
    }

}
